﻿// Jinx AJAX Framework
// Copyright (C) 2008 Blake Hegerle
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using Jinx.Bindings;
using Jinx.Controllers;
using Jinx.Polling;

namespace Jinx.Applications
{
    public class ApplicationContext : IDisposable
    {
        #region Delegates

        public delegate void ApplicationContextEvent(ApplicationContext ApplicationContext);

        #endregion

        private readonly BindingContext bindingContext;
        private readonly ControllerContext controllerContext;
        private readonly PollingPlace pollingPlace;

        public ApplicationContext()
        {
            controllerContext = new ControllerContext();
            bindingContext = new BindingContext();
            pollingPlace = new PollingPlace();
        }

        public ControllerContext ControllerContext
        {
            get { return controllerContext; }
        }

        public Token Token { get; set; }

        public BindingContext BindingContext
        {
            get { return bindingContext; }
        }

        public PollingPlace PollingPlace
        {
            get { return pollingPlace; }
        }

        public void StartUp()
        {
            if (OnApplicationContextStartUp != null)
                OnApplicationContextStartUp(this);
        }

        #region IDisposable Members

        public void Dispose()
        {
            if (OnApplicationContextDisposed != null)
                OnApplicationContextDisposed(this);
        }

        #endregion

        public event ApplicationContextEvent OnApplicationContextDisposed;
        public event ApplicationContextEvent OnApplicationContextStartUp;
    }
}